﻿function goBack() {
    location.href = "/Province/ProvinceList";
}

var table;
$(document).ready(function () {
    $("#rightResources").addClass("active");
    table = $('#CityTB').dataTable({
        "bServerSide": true, //这个用来指明是通过服务端来取数据
        "sAjaxSource": "/City/GetCitysInfo", //这个是请求的地址
        // "bProcessing": true, // 是否显示取数据时的那个等待提示
        "bFilter": false,
        "iDisplayLength": 15,
        "aoColumns": [
            { "mDataProp": "CityID", "sTitle": "CityID", "sDefaultContent": "" },
            { "mDataProp": "ProvinceName", "sTitle": "Province Name", "sDefaultContent": "" },
            { "mDataProp": "CityName", "sTitle": "City Name", "sDefaultContent": "" },
             { "mDataProp": "IsActive", "sTitle": "Is Active", "sDefaultContent": "" }
        ],
        "aoColumnDefs": [
            {
                "targets": [2], // 目标列位置，下标从0开始
                "data": "CityName", // 数据列名
                "render": function (data, type, full) { // 返回自定义内容

                        return "<a href='javascript:void(0)' onclick=\"javascript:updatainfo('" + full.CityID + "')\" class='Link'>" + data + "</a>";
                }
            },
             {
                 "targets": [3], // 目标列位置，下标从0开始
                 "data": "IsActive", // 数据列名
                 "render": function (data, type, full) { // 返回自定义内容
                     if (full.IsActive == 0) {
                         return "Active";
                     }
                     else {
                         return "InActive";
                     }
                 }
             },
            {
                "targets": 0, //第一列隐藏
                "visible": false,
                "searchable": false
            }
        ],
        "fnServerParams": function (aoData) { //查询条件
            aoData.push(
                { "name": "cityname", "value": $("#txt_cityname").val() },
                { "name": "provinceid", "value": $("#proList").val() },
                    { "name": "isactive", "value": $("#isActive").val() }
            );
        },
        "bLengthChange": false,
        "sPaginationType": "full_numbers"
    });


    $("#addBut").click(function () {
        location.href = "/City/CityAdd/" + $("#hidprovinceid").val();
    });


    /* Get the rows which are currently selected */
    function fnGetSelected(oTable) {
        var aReturn = new Array();
        var aTrs = table.fnGetNodes();
        for (var i = 0; i < aTrs.length; i++) {
            if ($(aTrs[i]).hasClass('row_selected')) {
                aReturn.push(aTrs[i]);
            }
        }
        return aReturn;
    }

    $("#Searchbtn").bind("click", function () { //按钮 触发table重新请求服务器
        table.fnDraw();
    });
});

function updatainfo(parameters) {
    if (parameters != undefined) {
        location.href = "/City/CityUpdate/" + parameters;
    } else {
        var selectdata = $("#CityTB").DataTable().rows('.selected').data();
        var selectleng = selectdata.length;
        if (selectleng == 1) {
            location.href = "/City/CityUpdate/" + selectdata[0].ToolID;
        } else {
            alert("只能选择一条数据");
        }
    }
}